home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_07_07
/
v7n7034a.txt
< prev
next >
Wrap
Text File
|
1989-09-03
|
1KB
|
48 lines
Listing 4
/*
* This program demonstrates the behavior of install when it
* tries to add a definition that is too big to fit in the
* table and the table ends near the end of a memory segment.
* This program has been compiled and tested with Microsoft C
* 5.1 using the compact, large and huge memory models.
*/
#include <stdio.h>
#include <string.h>
#define MAXCHARS 65535
#define ROOM 3
static char ndtable[MAXCHARS];
static char *endtab = &ndtable[MAXCHARS];
static char *nexttab = &ndtable[MAXCHARS - ROOM];
void install(const char *name, const char *defn)
{
size_t dlen, nlen;
nlen = strlen(name) + 1;
dlen = strlen(defn) + 1;
if (nexttab + nlen + dlen > endtab)
printf("too many definitions");
else
{
printf("there's room!?");
/* ... install the definition ... */
}
printf(" (%p)\n", nexttab + nlen + dlen);
}
void main(void)
{
printf("ndtable = %p\n", ndtable);
printf("endtab = %p\n", endtab);
printf("nexttab = %p\n", nexttab);
install("MAX", "100");
}